<!--  Ofri Keidar 302933981 group 05 -->

<%@page import="view.WebCommons"%>
<%@page import="model.database.DBException"%>
<%@page import="controller.CommonValues"%>
<%@page import="controller.EmployeeController"%>
<%@page import="java.util.List" %>
<%@page import="java.util.Map" %>
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<link rel="stylesheet" href="../../style/myTemplate/style.css"
	type="text/css">
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>All products in store</title>
</head>
<body>

	<span class="customHeader2">All products in store</span>
	
<%
	try {
			
		// extract controller from session
		EmployeeController controller = (EmployeeController) session.getAttribute(WebCommons.CONTROLLER);
		
		// try getting details of all products in store
		List<Map<String,String>> productsDetails = controller.getProducts();
		%>

		<div id="page" style="width: auto;">
			<div class="post">
				<div id="sidebar" style="width: auto;">
					<table border=2>
						<%
						// column names
						%>
						<tr>
							<td><span class="customMenuOption">Product's Name</span></td>
							<td><span class="customMenuOption">Price</span></td>
						</tr>
						<%
						// display data
						int numOfProducts = productsDetails.size();
						for (int i = 0; i < numOfProducts; i++) {
			
							// display details of current product
							Map<String, String> currProductDetails = productsDetails.get(i);
							%>
							<tr>
								<td><span class="customFormValue"><%=currProductDetails.get(CommonValues.NAME)%></span></td>
								<td><span class="customFormValue"><%=currProductDetails.get(CommonValues.PRICE)%></span></td>
							</tr>
							<%
						}
						%>
					</table>
				</div>	
			</div>
		</div>
		<%		

		} catch (DBException e) {
			
			// move to error page
			response.sendRedirect("../../commonPages/ErrorPage.jsp");
		}
	
	// return to main menu
	String menuPage = (String) session.getAttribute(WebCommons.MAIN_MANU);
	%>
	<div id="footer">
		<span class="myLink"><A HREF="<%="../../menus/" + menuPage%>">Back
				to Menu</A></span>
	</div>

</body>
</html>